package com.jiazhong.spring.rocketmq.延迟消息.生产;

import lombok.SneakyThrows;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;
import java.util.Date;

public class 延迟消息发送 {

    @SneakyThrows
    public static void main(String[] args) {
        DefaultMQProducer producer = new DefaultMQProducer("producer_group_b");
        producer.setNamesrvAddr("124.220.170.254:9876");
        producer.start();
        String topic = "TopicA";
        String tags = "yanchi";
        String body = "时间发送的";
        Message message = new Message(topic, tags, body.getBytes(StandardCharsets.UTF_8));
        message.setDelayTimeLevel(3);
        SendResult sendResult = producer.send(message);
        System.out.println(new Date() + "成功发送了" + sendResult);
        producer.shutdown();
    }
}
